var e = require("../../../@babel/runtime/helpers/objectSpread2"), t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Component({
    properties: {},
    data: {
        pluginShow: !1,
        popShow: !1,
        explainShow: !1,
        is_content: !1,
        is_notice: !1,
        invoice_type_index: 1,
        invoice_type_arr: [],
        invoice_header_index: 1,
        invoice_header_arr: [ {
            name: "个人",
            value: 1
        }, {
            name: "单位",
            value: 0
        } ],
        invoice_content_index: 1,
        invoice_content_arr: [],
        invoice_header_list: [],
        invoice_header_list_show: !1,
        invoice_explain: "",
        address: "",
        collect_name: "",
        gmf_taxpayer: "",
        gmf_bank: "",
        gmf_bank_admin: "",
        gmf_address: "",
        gmf_mobile: "",
        col_mobile: "",
        email: "",
        inputFocusName: "",
        tax_rate: 0
    },
    methods: {
        initData: function(e) {
            var t = e.address, a = e.sinvoice;
            if (1 == a.is_open && a.invoice_type.length >= 1) {
                var i = {
                    pluginShow: !0
                };
                i.invoice_type_arr = a.invoice_type, i.invoice_type_index = a.invoice_type[0].value;
                var n = a.content;
                n.push({
                    name: "不开发票",
                    value: 2
                }), i.invoice_content_arr = n, i.invoice_content_index = i.invoice_content_arr[0].value, 
                i.invoice_explain = a.notice, i.invoice_header_list = a.rises, i.tax_rate = a.tax_rate;
                var s = a.default_rise, o = s.personal, l = s.special, r = s.unit;
                i.personalRise = null != o ? o : {}, i.specialRise = null != l ? l : {}, i.unitRise = null != r ? r : {}, 
                this.data.address || (i.address = {
                    realname: t.realname,
                    mobile: t.mobile,
                    col_address: t.address
                }), this.setData(i), this.setDefaultData(this.data.personalRise, 1);
            }
        },
        setDefaultData: function(e, t) {
            var a = e.col_address, i = e.col_mobile, n = e.col_name, s = e.collect_name, o = e.email, l = e.gmf_address, r = e.gmf_bank, _ = e.gmf_bank_admin, c = e.gmf_mobile, d = e.gmf_taxpayer, m = {};
            1 == t ? (m.collect_name = null != s ? s : "", m.col_mobile = null != i ? i : "", 
            m.email = null != o ? o : "", m.address = {}) : 2 != t && 3 != t || (m.collect_name = null != s ? s : "", 
            m.gmf_taxpayer = null != d ? d : "", m.gmf_bank = null != r ? r : "", m.gmf_bank_admin = null != _ ? _ : "", 
            m.gmf_address = null != l ? l : "", m.gmf_mobile = null != c ? c : "", m.col_mobile = null != i ? i : "", 
            m.email = null != o ? o : "", m.address = {
                realname: null != n ? n : "",
                mobile: null != i ? i : "",
                col_address: null != a ? a : ""
            }), this.setData(m);
        },
        send: function() {
            var e = this.data, t = e.invoice_type_index, i = e.invoice_header_index, n = e.invoice_content_index, s = e.collect_name, o = e.gmf_taxpayer, l = e.gmf_bank, r = e.gmf_bank_admin, _ = e.gmf_address, c = e.gmf_mobile, d = e.col_mobile, m = e.email, u = e.address, p = e.tax_rate;
            if ("2" == this.data.invoice_content_index && this.data.is_content) return this.setData({
                popShow: !1
            }), !1;
            var h = {
                status: 2,
                apply: 1,
                invoice_type: t,
                rise_type: i,
                content: n,
                tax_rate: p
            };
            if (a._isTextEmpty(s)) return 0 == i || 2 == t ? a.tips("请输入单位名称") : a.tips("请输入发票抬头");
            if (h.collect_name = s, 2 == t || 0 == i) {
                if (a._isTextEmpty(o)) return a.tips("请输入纳税人识别号");
                if (2 == t) {
                    if (a._isTextEmpty(l)) return a.tips("请输入单位开户银行");
                    if (a._isTextEmpty(r)) return a.tips("请输入单位银行账号");
                    if (a._isTextEmpty(_)) return a.tips("请输入注册地址");
                    if (a._isTextEmpty(c)) return a.tips("请输入注册电话");
                }
                h.gmf_taxpayer = o, h.gmf_bank = l, h.gmf_bank_admin = r, h.gmf_address = _, h.gmf_mobile = c;
            }
            if (0 != t) {
                if (!u) return a.tips("请选择地址");
                h.col_address = u.col_address, h.col_name = u.realname, h.col_mobile = u.mobile;
            }
            0 == t && (h.email = m, h.col_mobile = d), this.triggerEvent("confirm", h), this.setData({
                popShow: !1
            });
        },
        openAddList: function() {
            this.triggerEvent("openAddList");
        },
        setAddress: function(e) {
            var t, a, i = {};
            i.realname = e.username, i.mobile = e.mobile, i.col_address = "".concat(e.province, " ").concat(e.city, " ").concat(e.district, " ").concat(null !== (t = e.street) && void 0 !== t ? t : "", " ").concat(null !== (a = e.address) && void 0 !== a ? a : ""), 
            this.setData({
                address: i
            });
        },
        setPopShow: function() {
            this.setData({
                popShow: !this.data.popShow
            });
        },
        setExplainShow: function() {
            this.setData({
                explainShow: !this.data.explainShow
            });
        },
        setTabsIndex: function(e) {
            var a = e.currentTarget.dataset, i = a.value, n = a.name;
            this.setData(t({}, n, i));
            var s = this.data, o = s.invoice_header_index, l = s.invoice_type_index, r = s.unitRise, _ = s.specialRise, c = s.personalRise;
            "invoice_type_index" == n && 2 == l ? this.setDefaultData(_, 3) : 0 == o ? this.setDefaultData(r, 2) : this.setDefaultData(c, 1);
        },
        setInvoiceHeaderListShow: function() {
            this.setData({
                invoice_header_list_show: !this.data.invoice_header_list_show
            });
        },
        setInvoiceHeader: function(t) {
            var a = t.currentTarget.dataset.content, i = a.collect_name, n = a.tax_num, s = a.bank, o = a.bank_admin, l = a.address, r = a.mobile, _ = {};
            1 == this.data.invoice_header_index ? _.collect_name = i : _ = {
                collect_name: i,
                gmf_taxpayer: n,
                gmf_bank: s,
                gmf_bank_admin: o,
                gmf_address: l,
                gmf_mobile: r
            }, this.setData(e({
                invoice_header_list_show: !1
            }, _));
        },
        clearInputText: function(e) {
            var a = e.currentTarget.dataset.name;
            this.setData(t({}, a, ""));
        },
        inputFocus: function(e) {
            var t = e.currentTarget.dataset.name;
            this.setData({
                inputFocusName: t
            });
        },
        inputBlur: function() {
            var e, a = this.data.inputFocusName;
            this.setData((t(e = {}, a, this.data[a].replace(/\s+/g, "")), t(e, "inputFocusName", ""), 
            e));
        }
    }
});